// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_float_from_decimal256_overflow") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "set enable_decimal256 = true;"
    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_0_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_0_nullable(f1 int, f2 decimalv3(39, 0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_0_nullable values (0, "900000000000000000000000000000000000000"),(1, "-900000000000000000000000000000000000000"),(2, "900000000000000000000000000000000000001"),(3, "-900000000000000000000000000000000000001"),(4, "999999999999999999999999999999999999999"),(5, "-999999999999999999999999999999999999999")
      ,(6, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_0_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_0_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_0_not_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_0_not_nullable(f1 int, f2 decimalv3(39, 0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_0_not_nullable values (0, "900000000000000000000000000000000000000"),(1, "-900000000000000000000000000000000000000"),(2, "900000000000000000000000000000000000001"),(3, "-900000000000000000000000000000000000001"),(4, "999999999999999999999999999999999999999"),(5, "-999999999999999999999999999999999999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_0_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_0_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_0_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_0_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_1_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_1_nullable(f1 int, f2 decimalv3(40, 0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_1_nullable values (0, "9000000000000000000000000000000000000000"),(1, "-9000000000000000000000000000000000000000"),(2, "9000000000000000000000000000000000000001"),(3, "-9000000000000000000000000000000000000001"),(4, "9999999999999999999999999999999999999999"),(5, "-9999999999999999999999999999999999999999")
      ,(6, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_1_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_1_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_1_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_1_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_1_not_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_1_not_nullable(f1 int, f2 decimalv3(40, 0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_1_not_nullable values (0, "9000000000000000000000000000000000000000"),(1, "-9000000000000000000000000000000000000000"),(2, "9000000000000000000000000000000000000001"),(3, "-9000000000000000000000000000000000000001"),(4, "9999999999999999999999999999999999999999"),(5, "-9999999999999999999999999999999999999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_1_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_1_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_1_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_1_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_2_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_2_nullable(f1 int, f2 decimalv3(40, 1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_2_nullable values (0, "900000000000000000000000000000000000000.0"),(1, "-900000000000000000000000000000000000000.0"),(2, "900000000000000000000000000000000000000.8"),(3, "-900000000000000000000000000000000000000.8"),(4, "900000000000000000000000000000000000000.9"),(5, "-900000000000000000000000000000000000000.9"),(6, "900000000000000000000000000000000000001.0"),(7, "-900000000000000000000000000000000000001.0"),(8, "900000000000000000000000000000000000001.8"),(9, "-900000000000000000000000000000000000001.8"),(10, "900000000000000000000000000000000000001.9"),(11, "-900000000000000000000000000000000000001.9"),(12, "999999999999999999999999999999999999999.0"),(13, "-999999999999999999999999999999999999999.0"),(14, "999999999999999999999999999999999999999.8"),(15, "-999999999999999999999999999999999999999.8"),(16, "999999999999999999999999999999999999999.9"),(17, "-999999999999999999999999999999999999999.9")
      ,(18, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_2_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_2_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_2_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_2_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_2_not_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_2_not_nullable(f1 int, f2 decimalv3(40, 1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_2_not_nullable values (0, "900000000000000000000000000000000000000.0"),(1, "-900000000000000000000000000000000000000.0"),(2, "900000000000000000000000000000000000000.8"),(3, "-900000000000000000000000000000000000000.8"),(4, "900000000000000000000000000000000000000.9"),(5, "-900000000000000000000000000000000000000.9"),(6, "900000000000000000000000000000000000001.0"),(7, "-900000000000000000000000000000000000001.0"),(8, "900000000000000000000000000000000000001.8"),(9, "-900000000000000000000000000000000000001.8"),(10, "900000000000000000000000000000000000001.9"),(11, "-900000000000000000000000000000000000001.9"),(12, "999999999999999999999999999999999999999.0"),(13, "-999999999999999999999999999999999999999.0"),(14, "999999999999999999999999999999999999999.8"),(15, "-999999999999999999999999999999999999999.8"),(16, "999999999999999999999999999999999999999.9"),(17, "-999999999999999999999999999999999999999.9");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_2_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_2_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_2_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_2_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_3_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_3_nullable(f1 int, f2 decimalv3(60, 0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_3_nullable values (0, "900000000000000000000000000000000000000000000000000000000000"),(1, "-900000000000000000000000000000000000000000000000000000000000"),(2, "900000000000000000000000000000000000000000000000000000000001"),(3, "-900000000000000000000000000000000000000000000000000000000001"),(4, "999999999999999999999999999999999999999999999999999999999999"),(5, "-999999999999999999999999999999999999999999999999999999999999")
      ,(6, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_3_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_3_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_3_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_3_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_3_not_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_3_not_nullable(f1 int, f2 decimalv3(60, 0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_3_not_nullable values (0, "900000000000000000000000000000000000000000000000000000000000"),(1, "-900000000000000000000000000000000000000000000000000000000000"),(2, "900000000000000000000000000000000000000000000000000000000001"),(3, "-900000000000000000000000000000000000000000000000000000000001"),(4, "999999999999999999999999999999999999999999999999999999999999"),(5, "-999999999999999999999999999999999999999999999999999999999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_3_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_3_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_3_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_3_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_4_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_4_nullable(f1 int, f2 decimalv3(60, 20)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_4_nullable values (0, "9000000000000000000000000000000000000000.00000000000000000000"),(1, "-9000000000000000000000000000000000000000.00000000000000000000"),(2, "9000000000000000000000000000000000000000.09999999999999999999"),(3, "-9000000000000000000000000000000000000000.09999999999999999999"),(4, "9000000000000000000000000000000000000000.90000000000000000000"),(5, "-9000000000000000000000000000000000000000.90000000000000000000"),(6, "9000000000000000000000000000000000000000.90000000000000000001"),(7, "-9000000000000000000000000000000000000000.90000000000000000001"),(8, "9000000000000000000000000000000000000000.99999999999999999999"),(9, "-9000000000000000000000000000000000000000.99999999999999999999"),(10, "9000000000000000000000000000000000000001.00000000000000000000"),(11, "-9000000000000000000000000000000000000001.00000000000000000000"),(12, "9000000000000000000000000000000000000001.09999999999999999999"),(13, "-9000000000000000000000000000000000000001.09999999999999999999"),(14, "9000000000000000000000000000000000000001.90000000000000000000"),(15, "-9000000000000000000000000000000000000001.90000000000000000000"),(16, "9000000000000000000000000000000000000001.90000000000000000001"),(17, "-9000000000000000000000000000000000000001.90000000000000000001"),(18, "9000000000000000000000000000000000000001.99999999999999999999"),(19, "-9000000000000000000000000000000000000001.99999999999999999999"),
      (20, "9999999999999999999999999999999999999999.00000000000000000000"),(21, "-9999999999999999999999999999999999999999.00000000000000000000"),(22, "9999999999999999999999999999999999999999.09999999999999999999"),(23, "-9999999999999999999999999999999999999999.09999999999999999999"),(24, "9999999999999999999999999999999999999999.90000000000000000000"),(25, "-9999999999999999999999999999999999999999.90000000000000000000"),(26, "9999999999999999999999999999999999999999.90000000000000000001"),(27, "-9999999999999999999999999999999999999999.90000000000000000001"),(28, "9999999999999999999999999999999999999999.99999999999999999999"),(29, "-9999999999999999999999999999999999999999.99999999999999999999")
      ,(30, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_4_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_4_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_4_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_4_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_4_not_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_4_not_nullable(f1 int, f2 decimalv3(60, 20)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_4_not_nullable values (0, "9000000000000000000000000000000000000000.00000000000000000000"),(1, "-9000000000000000000000000000000000000000.00000000000000000000"),(2, "9000000000000000000000000000000000000000.09999999999999999999"),(3, "-9000000000000000000000000000000000000000.09999999999999999999"),(4, "9000000000000000000000000000000000000000.90000000000000000000"),(5, "-9000000000000000000000000000000000000000.90000000000000000000"),(6, "9000000000000000000000000000000000000000.90000000000000000001"),(7, "-9000000000000000000000000000000000000000.90000000000000000001"),(8, "9000000000000000000000000000000000000000.99999999999999999999"),(9, "-9000000000000000000000000000000000000000.99999999999999999999"),(10, "9000000000000000000000000000000000000001.00000000000000000000"),(11, "-9000000000000000000000000000000000000001.00000000000000000000"),(12, "9000000000000000000000000000000000000001.09999999999999999999"),(13, "-9000000000000000000000000000000000000001.09999999999999999999"),(14, "9000000000000000000000000000000000000001.90000000000000000000"),(15, "-9000000000000000000000000000000000000001.90000000000000000000"),(16, "9000000000000000000000000000000000000001.90000000000000000001"),(17, "-9000000000000000000000000000000000000001.90000000000000000001"),(18, "9000000000000000000000000000000000000001.99999999999999999999"),(19, "-9000000000000000000000000000000000000001.99999999999999999999"),
      (20, "9999999999999999999999999999999999999999.00000000000000000000"),(21, "-9999999999999999999999999999999999999999.00000000000000000000"),(22, "9999999999999999999999999999999999999999.09999999999999999999"),(23, "-9999999999999999999999999999999999999999.09999999999999999999"),(24, "9999999999999999999999999999999999999999.90000000000000000000"),(25, "-9999999999999999999999999999999999999999.90000000000000000000"),(26, "9999999999999999999999999999999999999999.90000000000000000001"),(27, "-9999999999999999999999999999999999999999.90000000000000000001"),(28, "9999999999999999999999999999999999999999.99999999999999999999"),(29, "-9999999999999999999999999999999999999999.99999999999999999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_4_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_4_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_4_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_4_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_5_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_5_nullable(f1 int, f2 decimalv3(76, 0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_5_nullable values (0, "9000000000000000000000000000000000000000000000000000000000000000000000000000"),(1, "-9000000000000000000000000000000000000000000000000000000000000000000000000000"),(2, "9000000000000000000000000000000000000000000000000000000000000000000000000001"),(3, "-9000000000000000000000000000000000000000000000000000000000000000000000000001"),(4, "9999999999999999999999999999999999999999999999999999999999999999999999999999"),(5, "-9999999999999999999999999999999999999999999999999999999999999999999999999999")
      ,(6, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_5_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_5_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_5_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_5_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_5_not_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_5_not_nullable(f1 int, f2 decimalv3(76, 0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_5_not_nullable values (0, "9000000000000000000000000000000000000000000000000000000000000000000000000000"),(1, "-9000000000000000000000000000000000000000000000000000000000000000000000000000"),(2, "9000000000000000000000000000000000000000000000000000000000000000000000000001"),(3, "-9000000000000000000000000000000000000000000000000000000000000000000000000001"),(4, "9999999999999999999999999999999999999999999999999999999999999999999999999999"),(5, "-9999999999999999999999999999999999999999999999999999999999999999999999999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_5_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_5_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_5_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_5_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_6_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_6_nullable(f1 int, f2 decimalv3(76, 1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_6_nullable values (0, "900000000000000000000000000000000000000000000000000000000000000000000000000.0"),(1, "-900000000000000000000000000000000000000000000000000000000000000000000000000.0"),(2, "900000000000000000000000000000000000000000000000000000000000000000000000000.8"),(3, "-900000000000000000000000000000000000000000000000000000000000000000000000000.8"),(4, "900000000000000000000000000000000000000000000000000000000000000000000000000.9"),(5, "-900000000000000000000000000000000000000000000000000000000000000000000000000.9"),(6, "900000000000000000000000000000000000000000000000000000000000000000000000001.0"),(7, "-900000000000000000000000000000000000000000000000000000000000000000000000001.0"),(8, "900000000000000000000000000000000000000000000000000000000000000000000000001.8"),(9, "-900000000000000000000000000000000000000000000000000000000000000000000000001.8"),(10, "900000000000000000000000000000000000000000000000000000000000000000000000001.9"),(11, "-900000000000000000000000000000000000000000000000000000000000000000000000001.9"),(12, "999999999999999999999999999999999999999999999999999999999999999999999999999.0"),(13, "-999999999999999999999999999999999999999999999999999999999999999999999999999.0"),(14, "999999999999999999999999999999999999999999999999999999999999999999999999999.8"),(15, "-999999999999999999999999999999999999999999999999999999999999999999999999999.8"),(16, "999999999999999999999999999999999999999999999999999999999999999999999999999.9"),(17, "-999999999999999999999999999999999999999999999999999999999999999999999999999.9")
      ,(18, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_6_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_6_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_6_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_6_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_6_not_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_6_not_nullable(f1 int, f2 decimalv3(76, 1)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_6_not_nullable values (0, "900000000000000000000000000000000000000000000000000000000000000000000000000.0"),(1, "-900000000000000000000000000000000000000000000000000000000000000000000000000.0"),(2, "900000000000000000000000000000000000000000000000000000000000000000000000000.8"),(3, "-900000000000000000000000000000000000000000000000000000000000000000000000000.8"),(4, "900000000000000000000000000000000000000000000000000000000000000000000000000.9"),(5, "-900000000000000000000000000000000000000000000000000000000000000000000000000.9"),(6, "900000000000000000000000000000000000000000000000000000000000000000000000001.0"),(7, "-900000000000000000000000000000000000000000000000000000000000000000000000001.0"),(8, "900000000000000000000000000000000000000000000000000000000000000000000000001.8"),(9, "-900000000000000000000000000000000000000000000000000000000000000000000000001.8"),(10, "900000000000000000000000000000000000000000000000000000000000000000000000001.9"),(11, "-900000000000000000000000000000000000000000000000000000000000000000000000001.9"),(12, "999999999999999999999999999999999999999999999999999999999999999999999999999.0"),(13, "-999999999999999999999999999999999999999999999999999999999999999999999999999.0"),(14, "999999999999999999999999999999999999999999999999999999999999999999999999999.8"),(15, "-999999999999999999999999999999999999999999999999999999999999999999999999999.8"),(16, "999999999999999999999999999999999999999999999999999999999999999999999999999.9"),(17, "-999999999999999999999999999999999999999999999999999999999999999999999999999.9");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_6_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_6_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_6_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_6_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_7_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_7_nullable(f1 int, f2 decimalv3(76, 10)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_7_nullable values (0, "900000000000000000000000000000000000000000000000000000000000000000.0000000000"),(1, "-900000000000000000000000000000000000000000000000000000000000000000.0000000000"),(2, "900000000000000000000000000000000000000000000000000000000000000000.0999999999"),(3, "-900000000000000000000000000000000000000000000000000000000000000000.0999999999"),(4, "900000000000000000000000000000000000000000000000000000000000000000.9000000000"),(5, "-900000000000000000000000000000000000000000000000000000000000000000.9000000000"),(6, "900000000000000000000000000000000000000000000000000000000000000000.9000000001"),(7, "-900000000000000000000000000000000000000000000000000000000000000000.9000000001"),(8, "900000000000000000000000000000000000000000000000000000000000000000.9999999999"),(9, "-900000000000000000000000000000000000000000000000000000000000000000.9999999999"),(10, "900000000000000000000000000000000000000000000000000000000000000001.0000000000"),(11, "-900000000000000000000000000000000000000000000000000000000000000001.0000000000"),(12, "900000000000000000000000000000000000000000000000000000000000000001.0999999999"),(13, "-900000000000000000000000000000000000000000000000000000000000000001.0999999999"),(14, "900000000000000000000000000000000000000000000000000000000000000001.9000000000"),(15, "-900000000000000000000000000000000000000000000000000000000000000001.9000000000"),(16, "900000000000000000000000000000000000000000000000000000000000000001.9000000001"),(17, "-900000000000000000000000000000000000000000000000000000000000000001.9000000001"),(18, "900000000000000000000000000000000000000000000000000000000000000001.9999999999"),(19, "-900000000000000000000000000000000000000000000000000000000000000001.9999999999"),
      (20, "999999999999999999999999999999999999999999999999999999999999999999.0000000000"),(21, "-999999999999999999999999999999999999999999999999999999999999999999.0000000000"),(22, "999999999999999999999999999999999999999999999999999999999999999999.0999999999"),(23, "-999999999999999999999999999999999999999999999999999999999999999999.0999999999"),(24, "999999999999999999999999999999999999999999999999999999999999999999.9000000000"),(25, "-999999999999999999999999999999999999999999999999999999999999999999.9000000000"),(26, "999999999999999999999999999999999999999999999999999999999999999999.9000000001"),(27, "-999999999999999999999999999999999999999999999999999999999999999999.9000000001"),(28, "999999999999999999999999999999999999999999999999999999999999999999.9999999999"),(29, "-999999999999999999999999999999999999999999999999999999999999999999.9999999999")
      ,(30, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_7_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_7_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_7_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_7_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_7_not_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_7_not_nullable(f1 int, f2 decimalv3(76, 10)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_7_not_nullable values (0, "900000000000000000000000000000000000000000000000000000000000000000.0000000000"),(1, "-900000000000000000000000000000000000000000000000000000000000000000.0000000000"),(2, "900000000000000000000000000000000000000000000000000000000000000000.0999999999"),(3, "-900000000000000000000000000000000000000000000000000000000000000000.0999999999"),(4, "900000000000000000000000000000000000000000000000000000000000000000.9000000000"),(5, "-900000000000000000000000000000000000000000000000000000000000000000.9000000000"),(6, "900000000000000000000000000000000000000000000000000000000000000000.9000000001"),(7, "-900000000000000000000000000000000000000000000000000000000000000000.9000000001"),(8, "900000000000000000000000000000000000000000000000000000000000000000.9999999999"),(9, "-900000000000000000000000000000000000000000000000000000000000000000.9999999999"),(10, "900000000000000000000000000000000000000000000000000000000000000001.0000000000"),(11, "-900000000000000000000000000000000000000000000000000000000000000001.0000000000"),(12, "900000000000000000000000000000000000000000000000000000000000000001.0999999999"),(13, "-900000000000000000000000000000000000000000000000000000000000000001.0999999999"),(14, "900000000000000000000000000000000000000000000000000000000000000001.9000000000"),(15, "-900000000000000000000000000000000000000000000000000000000000000001.9000000000"),(16, "900000000000000000000000000000000000000000000000000000000000000001.9000000001"),(17, "-900000000000000000000000000000000000000000000000000000000000000001.9000000001"),(18, "900000000000000000000000000000000000000000000000000000000000000001.9999999999"),(19, "-900000000000000000000000000000000000000000000000000000000000000001.9999999999"),
      (20, "999999999999999999999999999999999999999999999999999999999999999999.0000000000"),(21, "-999999999999999999999999999999999999999999999999999999999999999999.0000000000"),(22, "999999999999999999999999999999999999999999999999999999999999999999.0999999999"),(23, "-999999999999999999999999999999999999999999999999999999999999999999.0999999999"),(24, "999999999999999999999999999999999999999999999999999999999999999999.9000000000"),(25, "-999999999999999999999999999999999999999999999999999999999999999999.9000000000"),(26, "999999999999999999999999999999999999999999999999999999999999999999.9000000001"),(27, "-999999999999999999999999999999999999999999999999999999999999999999.9000000001"),(28, "999999999999999999999999999999999999999999999999999999999999999999.9999999999"),(29, "-999999999999999999999999999999999999999999999999999999999999999999.9999999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_7_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_7_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_7_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_7_not_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_8_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_8_nullable(f1 int, f2 decimalv3(76, 37)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_8_nullable values (0, "900000000000000000000000000000000000000.0000000000000000000000000000000000000"),(1, "-900000000000000000000000000000000000000.0000000000000000000000000000000000000"),(2, "900000000000000000000000000000000000000.0999999999999999999999999999999999999"),(3, "-900000000000000000000000000000000000000.0999999999999999999999999999999999999"),(4, "900000000000000000000000000000000000000.9000000000000000000000000000000000000"),(5, "-900000000000000000000000000000000000000.9000000000000000000000000000000000000"),(6, "900000000000000000000000000000000000000.9000000000000000000000000000000000001"),(7, "-900000000000000000000000000000000000000.9000000000000000000000000000000000001"),(8, "900000000000000000000000000000000000000.9999999999999999999999999999999999999"),(9, "-900000000000000000000000000000000000000.9999999999999999999999999999999999999"),(10, "900000000000000000000000000000000000001.0000000000000000000000000000000000000"),(11, "-900000000000000000000000000000000000001.0000000000000000000000000000000000000"),(12, "900000000000000000000000000000000000001.0999999999999999999999999999999999999"),(13, "-900000000000000000000000000000000000001.0999999999999999999999999999999999999"),(14, "900000000000000000000000000000000000001.9000000000000000000000000000000000000"),(15, "-900000000000000000000000000000000000001.9000000000000000000000000000000000000"),(16, "900000000000000000000000000000000000001.9000000000000000000000000000000000001"),(17, "-900000000000000000000000000000000000001.9000000000000000000000000000000000001"),(18, "900000000000000000000000000000000000001.9999999999999999999999999999999999999"),(19, "-900000000000000000000000000000000000001.9999999999999999999999999999999999999"),
      (20, "999999999999999999999999999999999999999.0000000000000000000000000000000000000"),(21, "-999999999999999999999999999999999999999.0000000000000000000000000000000000000"),(22, "999999999999999999999999999999999999999.0999999999999999999999999999999999999"),(23, "-999999999999999999999999999999999999999.0999999999999999999999999999999999999"),(24, "999999999999999999999999999999999999999.9000000000000000000000000000000000000"),(25, "-999999999999999999999999999999999999999.9000000000000000000000000000000000000"),(26, "999999999999999999999999999999999999999.9000000000000000000000000000000000001"),(27, "-999999999999999999999999999999999999999.9000000000000000000000000000000000001"),(28, "999999999999999999999999999999999999999.9999999999999999999999999999999999999"),(29, "-999999999999999999999999999999999999999.9999999999999999999999999999999999999")
      ,(30, null);
    """

    sql "set enable_strict_cast=true;"
    qt_sql_8_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_8_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_8_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_8_nullable order by 1;'

    sql "drop table if exists test_cast_to_float_from_decimal256_overflow_8_not_nullable;"
    sql "create table test_cast_to_float_from_decimal256_overflow_8_not_nullable(f1 int, f2 decimalv3(76, 37)) properties('replication_num'='1');"
    sql """insert into test_cast_to_float_from_decimal256_overflow_8_not_nullable values (0, "900000000000000000000000000000000000000.0000000000000000000000000000000000000"),(1, "-900000000000000000000000000000000000000.0000000000000000000000000000000000000"),(2, "900000000000000000000000000000000000000.0999999999999999999999999999999999999"),(3, "-900000000000000000000000000000000000000.0999999999999999999999999999999999999"),(4, "900000000000000000000000000000000000000.9000000000000000000000000000000000000"),(5, "-900000000000000000000000000000000000000.9000000000000000000000000000000000000"),(6, "900000000000000000000000000000000000000.9000000000000000000000000000000000001"),(7, "-900000000000000000000000000000000000000.9000000000000000000000000000000000001"),(8, "900000000000000000000000000000000000000.9999999999999999999999999999999999999"),(9, "-900000000000000000000000000000000000000.9999999999999999999999999999999999999"),(10, "900000000000000000000000000000000000001.0000000000000000000000000000000000000"),(11, "-900000000000000000000000000000000000001.0000000000000000000000000000000000000"),(12, "900000000000000000000000000000000000001.0999999999999999999999999999999999999"),(13, "-900000000000000000000000000000000000001.0999999999999999999999999999999999999"),(14, "900000000000000000000000000000000000001.9000000000000000000000000000000000000"),(15, "-900000000000000000000000000000000000001.9000000000000000000000000000000000000"),(16, "900000000000000000000000000000000000001.9000000000000000000000000000000000001"),(17, "-900000000000000000000000000000000000001.9000000000000000000000000000000000001"),(18, "900000000000000000000000000000000000001.9999999999999999999999999999999999999"),(19, "-900000000000000000000000000000000000001.9999999999999999999999999999999999999"),
      (20, "999999999999999999999999999999999999999.0000000000000000000000000000000000000"),(21, "-999999999999999999999999999999999999999.0000000000000000000000000000000000000"),(22, "999999999999999999999999999999999999999.0999999999999999999999999999999999999"),(23, "-999999999999999999999999999999999999999.0999999999999999999999999999999999999"),(24, "999999999999999999999999999999999999999.9000000000000000000000000000000000000"),(25, "-999999999999999999999999999999999999999.9000000000000000000000000000000000000"),(26, "999999999999999999999999999999999999999.9000000000000000000000000000000000001"),(27, "-999999999999999999999999999999999999999.9000000000000000000000000000000000001"),(28, "999999999999999999999999999999999999999.9999999999999999999999999999999999999"),(29, "-999999999999999999999999999999999999999.9999999999999999999999999999999999999");
    """

    sql "set enable_strict_cast=true;"
    qt_sql_8_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_8_not_nullable order by 1;'

    sql "set enable_strict_cast=false;"
    qt_sql_8_non_strict 'select f1, cast(f2 as float) from test_cast_to_float_from_decimal256_overflow_8_not_nullable order by 1;'

}